package logic

import (
	"context"
	"srv/cart"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type DelLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelLogic {
	return &DelLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DelLogic) Del(req *types.DelcartRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	cleveCart, err := l.svcCtx.Cart.CleveCart(l.ctx, &cart.CleveCartRequest{UserId: int64(req.UserId)})
	if err != nil {
		return &types.Response{
			Msg:  "清空购物车失败",
			Cate: 500,
			Data: nil,
		}, err
	}
	return &types.Response{
		Msg:  "清空购物车成功",
		Cate: 200,
		Data: map[string]interface{}{
			"cleve": cleveCart,
		},
	}, err
}
